this.name					= "CT_thargon";
this.author					= "Thargoid";
this.copyright				= "Creative Commons: attribution, non-commercial, sharealike.";
this.description				= "AI-actions script for the captured thargon";
this.version				= "1.0";

this.shipSpawned = function()
	{
	missionVariables.CT_thargonCount -=1;
	}

this.shipWasScooped = function(scooper)
	{
	if(scooper.isPlayer)
		{
		missionVariables.CT_thargonCount +=1;
		if(missionVariables.CT_thargonCount == 1)
			{
			player.ship.awardEquipment("EQ_CT_MINE");	
			}
		}
	}

this.locatePlayer = function()
	{
	this.playerArray = system.shipsWithPrimaryRole("player");
	if(this.playerArray.length == 0) // where'd they go?
		{
		this.ship.remove(); // If no player, then we can remove the thargon.
		}
	else
		{
		this.ship.target = this.playerArray[0];
		this.ship.reactToAIMessage("PLAYER_FOUND");
		}
	}

this.findPlayerHostiles = function()
	{
	function isHostileToPlayer(entity) 
		{ 
		return (entity.isThargoid || (entity.isShip && entity.target && entity.target == player.ship && entity.hasHostileTarget));
		}

	if(this.ship.target == player.ship && player.ship.target && player.ship.target.bounty > 10)
		{
		this.ship.target = player.ship.target;
		this.ship.reactToAIMessage("HOSTILE_FOUND");
		}
	else
		{
		var targets = system.filteredEntities(this, isHostileToPlayer, this.ship, this.ship.scannerRange);
		if(targets.length > 0)
			{
			this.ship.target = targets[0];
			this.ship.reactToAIMessage("HOSTILE_FOUND");
			}
		else
			{
			this.ship.reactToAIMessage("NO_HOSTILE_FOUND");
			}
		}
	}

this.fireCheck = function()
	{
	if((this.ship.target.hasRole("CT_thargon")) || (player.ship.target == this.ship && this.ship.target.isPlayer))
		{
		this.ship.reactToAIMessage("FRIENDLY_FIRE");
		}
	else
		{
		this.ship.reactToAIMessage("ENEMY_FIRE");
		}
	}

this.shipDestroyedTarget = function(target)
	{
	player.score += 1;
	player.credits += target.bounty;
	player.consoleMessage("Thargon kill - " + target.name + " : " + target.bounty + "₢ awarded.", 5);
	log("Thargon kill - " + target.name + " : " + target.bounty);
	}

this.shipDied = function(whom, why)
	{
	if(whom && whom.isValid)
		{
		player.consoleMessage("Contact lost with Thargon fighter", 5);
		}
	}